//
//  BlurBackgroudNode.hpp
//  client
//
//  Created by will on 01/11/2017.
//
//

#ifndef BlurBackgroudNode_hpp
#define BlurBackgroudNode_hpp


#include "cocos2d.h"
#include "ui/UIWidget.h"
#include "ui/UILayout.h"


class BlurBackgroudNode : public cocos2d::ui::Layout
{
    typedef std::function<void(bool)> EventFuntion;
public:
    static BlurBackgroudNode* create();
    
public:
    BlurBackgroudNode();
    ~BlurBackgroudNode();
    
    void setEventCallback(const EventFuntion& func);
    void setBlurTargetNode(cocos2d::Node* target);
    
protected:
    virtual bool init() override;

    virtual void visit(cocos2d::Renderer* renderer, const cocos2d::Mat4 &parentTransform, uint32_t parentFlags) override;
    
    void drawFBOTexture(const cocos2d::Mat4 &mat4);
    
    void captureTarget();
private:
    cocos2d::FBOCommand _fboCommand;
    cocos2d::CustomCommand _drawCommand;
    cocos2d::GLProgram* _blurProgram;
    cocos2d::Node* _target;
    bool _rendered;
    EventFuntion _delegate;
    
};

#endif /* BlurBackgroudNode_hpp */
